{$contents}

{literal}
<div style="text-align:left; padding:10px; clear:both;">
<h2>Source</h2>

<pre class="code">
&lt;?php
function nameCall ( DomFgTreeNode $node, $element, DomController $controller ) {
	$node->name($element['name']);
	$node->link( $controller->getUrl() );
	$node->icon( $node->isLeaf() ? 'file' : 'folder');
}

$panel = array(
	'title' => 'Tree',
	'layout' => 'table',
	'style' => 'width:270px; float:left;',
	'layoutConfig' => array(
		'columns' => 1,
	),
	'action' => $this->getUrl('pools/'),
	'items' => array(
		array(
			'id' => 'itemsTree',
			'type' => 'tree',
			'source' => array(
				'query' => TreeItem::dataQuery()->orderBy('t.name DESC'),
				'parentIdField' => 'parent',
				'idField' => 'id',
				'nameField' => 'name',
				'callback' => 'nameCall',
				'callbackArgs' => array($this),
			),
		),
	),
);








function generateTreeSource( DomController $controller, $parentId = NULL, $parentNode = NULL ) {
	$list = array();
	$query = TreeItem::query()
		->where( 't.parent '.($parentId ? '='.(int)$parentId : '<=> NULL') )
		->orderBy('t.name DESC');
		
	foreach( $query->commit() as $element ) {
		$node = new DomFgTreeNode( $element->name );
		generateTreeSource( $controller, $element->id, $node );
		$node->link( $controller->getUrl() );
		if( $parentNode ) $parentNode->add( $node );
		$list[] = $node;
	}
	return $list;
}

$panel2 = array(
	'title' => 'Tree 2',
	'layout' => 'table',
	'style' => 'width:270px; float:left;',
	'layoutConfig' => array(
		'columns' => 1,
	),
	'action' => $this->getUrl('pools/'),
	'items' => array(
		array(
			'id' => 'itemsTree2',
			'type' => 'tree',
			'source' => generateTreeSource( $this ),
		),
	),
);


$this->view->contents = DomFg::render( $panel ) . DomFg::render( $panel2 );
?&gt;
</pre>
</div>
{/literal}